<?php
use yii\helpers\Html;
use kartik\form\ActiveForm;
use admin\models\db\BuildingOrders;
use common\assets\WangEditorV4;

/* @var $this yii\web\View */
/* @var $model admin\modules\buildingOrder\models\forms\BuildingOrderMessages */
/* @var $form \kartik\form\ActiveForm */

WangEditorV4::register($this)

;$css = <<<CSS
/*.media-body img,.media-body video{
    max-width: 100%;
}*/
CSS;
$this->registerCss($css);
?>

<div class="building-order-messages-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'set_bo_status')->dropDownList(BuildingOrders::getStatusDesc()) ?>

    <?=$form->field($model, 'message')->textarea(['class' => "leaveMessage hidden"]) ?>
    <div class="openEditor"></div>

	<?php if (!Yii::$app->request->isAjax){ ?>
	  	<div class="form-group">
	        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', '新建') : Yii::t('app', '更新'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
	    </div>
	<?php } ?>

    <?php ActiveForm::end(); ?>
    
</div>

<?php
$uploadImgServer = Yii::$app->urlManager->createUrl('/pub/ajax/wang-upload-images');
$uploadVideoServer = Yii::$app->urlManager->createUrl('/pub/ajax/wang-upload-video');
$js = <<<JS
if (typeof editor !== "undefined") {
    delete editor;
}
var editor = new window.wangEditor('.openEditor')
editor.config.height = 200
// editor.config.withCredentials = true
editor.config.uploadImgServer = "{$uploadImgServer}";
editor.config.uploadImgMaxSize = 2 * 1024 * 1024 // 2M
editor.config.uploadImgMaxLength = 10 // 一次最多上传 10 个图片
//editor.config.uploadVideoServer = "{$uploadVideoServer}";
//editor.config.uploadVideoAccept = ['mp4', 'MP4', 'mov', 'MOV'];
//editor.config.uploadVideoMaxSize = 20 * 1024 * 1024 // 20M
editor.config.onchange = function (html) {
    $('.leaveMessage').val(html)
}
editor.create()
JS;

$this->registerJs($js);
?>